<template>
  <div>

    <el-dialog :close-on-click-modal="false" title="认筹租赁手续费" class="tl size_13" width="60%" :visible.sync="dialogVisible">
      <el-button style="margin-bottom:10px" :loading="$store.state.isLoading" size="mini" @click="openAdd" type="primary">添加手续费</el-button>
      <el-table stripe :data="list" style="width: 100%">
        <!-- @selection-change="handleSelectionChange" -->
        <!-- <el-table-column type="selection" class="tc" width="35"></el-table-column> -->

        <el-table-column label="赎回月份" min-width="320">
          <template slot-scope="scope">
            {{scope.row.shsj }}
          </template>
        </el-table-column>
        <el-table-column label="手续费比例" min-width="320">
          <template slot-scope="scope">
            {{scope.row.money}}‰
          </template>
        </el-table-column>
        <!-- <el-table-column label="时间信息" min-width="220">
          <template slot-scope="scope">
            <div class="tab_div">
              <div>
                <span>添加时间：</span>
                <span>{{ scope.row.created_time | getTimeFormat }}</span>
              </div>
              <div>
                <span>修改时间：</span>
                <span>{{ scope.row.update_time | getTimeFormat }}</span>
              </div>
            </div>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="激活" min-width="120">
          <template slot-scope="scope">
            <el-switch class="zdySwith" :width="82" v-model="scope.row.show" active-color="#1aad19" inactive-color="#ffffff" active-text="on" inactive-text="off" active-value="1" @change="switchEdit($event, scope.row)" inactive-value="0"></el-switch>
          </template>
        </el-table-column> -->
        <el-table-column label="操作" min-width="220">
          <template slot-scope="scope">
            <el-row class="myblank">
              <el-button :loading="$store.state.isLoading" size="mini" @click="openEdit(scope.row)" type="primary">编辑</el-button>
              <el-button :loading="$store.state.isLoading" size="mini" type="danger" @click="openDelete(scope.row.id)">删除</el-button>
            </el-row>
          </template>
        </el-table-column>
      </el-table>
      <!-- <el-button style="margin-top:10px" :disabled="multipleSelection && multipleSelection.length > 0 ? false:true" :loading="$store.state.isLoading" size="mini" @click="openAdd" type="danger">批量删除</el-button> -->

    </el-dialog>

    <el-dialog :close-on-click-modal="false" :title="isEdit ? '编辑' : '添加'" class="tl size_13" width="800px" :visible.sync="dialogFormVisible">
      <el-form :model="edit_data" ref="form" label-width="120px">
        <el-form-item label="赎回月份：">
          <el-col :span="12">
            <el-input type="number" :rows="6" clearable placeholder="请输入" v-model="edit_data.shsj" autocomplete="off"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="手续费比例：">
          <el-col :span="12">
            <el-input type="number" :rows="6" clearable placeholder="请输入" v-model="edit_data.money" autocomplete="off">
              <span slot="append">%</span>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item>
          <el-button :loading="$store.state.isLoading" type="primary" @click="saveEdit">保 存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- <keep-alive>
      <component :is="'xzuser'" :show="shows" :isAll="false" showType="list" @sendShop="getSend" @isshow="getShow"></component>
    </keep-alive> -->
  </div>
</template>
<script>
// import xzuser from "@/components/currency/xz_user.vue";
import uploadpic from "@/components/page/pic/up_pic";
// import { dzPickupProductDialogSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data() {
    return {
      numberForm: {},
      numberVisiable: false,
      numberIden: "",
      productList: [],
      nowId: "",
      dialogVisible: false,
      queryObj: {},
      searchDataInfo: {},
      current: "",
      shows: false,
      isEdit: false,
      dialogFormVisible: false,
      edit_data: {
        piclink: "",
      },
      tableLoading: false,
      list: [],
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      multipleSelection: [],
    };
  },
  components: {
    uploadpic,
  },
  methods: {
    getShow(val) {
      this.shows = val;
    },
    getSend(info) {
      this.edit_data.username = info.username;
      this.edit_data.uid = info.id;
    },
    xzshop() {
      this.shows = true;
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    moreDelete() {
      //批量删除
      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思",
        }).then((willDelete) => {
          if (willDelete.value) {
            this.$api.getDz.del_rent_fee({ id_str: str }).then((res) => {
              if (res.data.code == 200) {
                this.$swal("删除成功！", res.data.result, "success");
                this.getNewsAll();
              } else {
                this.$swal("删除失败！", res.data.result, "error");
              }
            });
          }
        });
      }
    },
    openDelete(id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          this.$api.getDz.del_rent_fee({ id: id }).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", res.data.result, "success");
              this.getNewsAll();
            } else {
              this.$swal("删除失败！", res.data.result, "error");
            }
          });
        }
      });
    },

    openAdd() {
      this.edit_data = {
        id_str: [],
      };
      this.isEdit = false;
      this.dialogFormVisible = true;
    },
    onSuccess(pic) {
      this.edit_data.piclink = pic;
    },
    openEdit(item) {
      this.isEdit = true;
      this.edit_data = JSON.parse(JSON.stringify(item));
      this.dialogFormVisible = true;
    },
    receive_search(obj) {
      this.currentPage = 1;
      this.searchAll = obj;
      this.getNewsAll();
    },
    handleSwitch(val, item) {
      var params = item;
      params.show = val;
      this.$api.getDz.edit_rent_fee(params).then((res) => {
        if (res.data.code != 200) {
          this.$swal("编辑失败！", res.data.result, "error");
          this.getNewsAll();
        }
      });
    },

    sorta(a, b) {
      return b - a;
    },
    sortNew(index, item) {
      var params = item;
      params.sort = item.sort;
      this.$api.getDz.edit_rent_fee(params).then((res) => {
        if (res.data.code == 200) {
          return;
        } else {
          this.$swal("编辑失败！", res.data.result, "error");
          this.getNewsAll();
        }
      });
    },
    saveEdit() {
      var params = JSON.parse(JSON.stringify(this.edit_data)) || {};
      params.rsid = this.nowId;
      if (this.isEdit == false) {
        this.$api.getDz.add_rent_fee(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.currentPage = 1;
            this.getNewsAll();
            this.$swal("添加成功！", res.data.result, "success");
          } else {
            this.$swal("添加失败！", res.data.result, "error");
          }
        });
      } else {
        this.$api.getDz.edit_rent_fee(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.getNewsAll();
            this.$swal("编辑成功！", res.data.result, "success");
          } else {
            this.$swal("编辑失败！", res.data.result, "error");
          }
        });
      }
    },
    getNewsAll() {
      this.tableLoading = true;
      var params = {};
      params = JSON.parse(JSON.stringify(this.searchAll));
      //   params.page = this.currentPage || 1;
      //   params.page_size = this.pageSize || "";
      for (var i in params) {
        if (!params[i]) {
          params[i] = "";
        }
      }
      var query = JSON.parse(JSON.stringify(this.queryObj || {}));
      var obj = Object.assign(query, params);
      obj.rsid = this.nowId;
      this.$api.getDz.get_rent_fee(obj).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        setTimeout(() => {
          this.tableLoading = false;
        }, 200);
      });
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.getNewsAll();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getNewsAll();
    },
    open(id) {
      this.nowId = id;
      this.dialogVisible = true;
      this.getNewsAll();
    },
  },
  created() {
    if (this.$route.query) {
      this.queryObj = this.$route.query;
      if (this.$route.query.page) {
        this.currentPage = this.$route.query.page;
        delete this.queryObj.page;
      }
    }
  },
  computed: {},
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}
/deep/.pickup_product_dialog .el-dialog__body {
  padding-top: 0;
}
</style>
